package com.qyer.lxp.service.product.impl;

import com.qyer.lxp.common.date.DateUtil;
import com.qyer.lxp.common.file.ProductCodeList;
import com.qyer.lxp.common.framework.core.BaseSpringService;
import com.qyer.lxp.common.framework.threadpool.AbstractAroundAdviceCallable;
import com.qyer.lxp.common.framework.threadpool.CommonThreadPool;
import com.qyer.lxp.common.framework.util.QyerUtils;
import com.qyer.lxp.dao.errorlog.TaskErrorLogMapper;
import com.qyer.lxp.dao.location.LocationMapper;
import com.qyer.lxp.dao.price.PriceMapper;
import com.qyer.lxp.dao.product.PickDropMapper;
import com.qyer.lxp.dao.product.ProductInfoMapper;
import com.qyer.lxp.lxdao.product.IProductDao;
import com.qyer.lxp.model.errorlog.TaskErrorLog;
import com.qyer.lxp.model.location.normal.Location;
import com.qyer.lxp.model.price.normal.Price;
import com.qyer.lxp.model.product.lastminute.*;
import com.qyer.lxp.model.product.normal.*;
import com.qyer.lxp.model.product.normal.ProductPickInfo;
import com.qyer.lxp.model.product.parameter.PickOrDropRequest;
import com.qyer.lxp.model.product.parameter.ProductCodeSearchRequest;
import com.qyer.lxp.model.product.parameter.ProductInfoRequest;
import com.qyer.lxp.model.product.parameter.SaleItemInfoRequest;
import com.qyer.lxp.service.mail.ISendEmailService;
import com.qyer.lxp.service.product.IProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 产品信息实现类
 * Created by jiangping on 16/5/13.
 */
@Service
public class ProductServiceImpl extends BaseSpringService implements IProductService {

    @Resource
    private IProductDao productDao;

    @Resource
    private ProductInfoMapper productInfoMapper;

    @Resource
    private PickDropMapper pickDropMapper;

    @Resource
    private LocationMapper locationMapper;

    @Resource
    private PriceMapper priceMapper;

    @Resource
    private TaskErrorLogMapper taskErrorLogMapper;

    @Resource
    private ISendEmailService sendEmailService;

    /**
     * 存储选好的商品code
     */
    private static List<String> list_code = new ArrayList<String>();


    /**
     * 获取产品code以及更新时间接口
     *
     * @param productCodeSearchRequest 获取产品信息调用参数
     * @return 返回产品信息
     * @throws Exception
     */
    public List<ProductCodeInfo> getUpdateProductInfo(ProductCodeSearchRequest productCodeSearchRequest) {
        if (null == productCodeSearchRequest) {
            return null;
        }

        try {
            return productDao.getUpdateProductInfo(productCodeSearchRequest);
        } catch (Exception e) {
            logger.error("调取力行接口失败：", e);
        }
        return null;
    }

    /**
     * 获取接送信息接口
     *
     * @param pickOrDropRequest 获取接机信息调用参数
     * @return 返回接机对象
     * @throws Exception
     */
    @Override
    public List<ProductPickInfo> getPickOrDrop(PickOrDropRequest pickOrDropRequest) {
        try {
            return productDao.getPickOrDrop(pickOrDropRequest);
        } catch (Exception e) {
            logger.error("调取力行接口失败：", e);
        }
        return null;
    }

    /**
     * 销售项目基本信息接口
     *
     * @param saleItemInfoRequest 请求参数
     * @return 返回销售基本信息对象
     * @throws Exception
     */
    @Override
    public List<SaleItemInfo> getSaleItemInfo(SaleItemInfoRequest saleItemInfoRequest) {
        try {
            return productDao.getSaleItemInfo(saleItemInfoRequest);
        } catch (Exception e) {
            logger.error("调取力行接口失败：", e);
        }
        return null;
    }

    /**
     * 获取接送信息接口
     * 根据产品 code 查询接送信息
     *
     * @param pickDropModelList 接送机参数
     * @throws Exception
     */
    @Override
    public void insertPickDrop(List<PickDropModel> pickDropModelList) {
        try {
            pickDropMapper.insertPickDrop(pickDropModelList);
        } catch (Exception e) {
            logger.error(e.toString());
        }
    }

    /**
     * 获取产品code
     *
     * @param type 0 全量商品，最早时间更新 1全量商品，昨天时间更新  2 选品列表商品，最早时间更新  3选品列表商品，昨天时间更新
     * @return
     */
    @Override
    public Map<String, String> getProductCode(int type) {
        try {
            if (type == 2 || type == 3) {
                list_code = ProductCodeList.getInstance().getProductCodeList();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("读取选品列表加载到内存失败",e);
        }

        //实例化预警所有的启动任务
        Map<String, String> mapProductCode = new HashMap<String, String>();
        ProductCodeSearchRequest productCodeSearchRequest = new ProductCodeSearchRequest();
        try {
            if (type == 0 || type == 2) { //最早时间更新
                //获取全量日期
                productCodeSearchRequest.setUpdateDateStart(DateUtil.convertDate("2014-01-01"));
            } else if (type == 1 || type == 3) { //昨天时间更新
                //获取昨天的日期
                String yesterday = DateUtil.getPreviousDateTimeString("yyyy-MM-dd");
                logger.info("日期为：" + yesterday);
                productCodeSearchRequest.setUpdateDateStart(DateUtil.convertDate(yesterday));
            }

        } catch (Exception e) {
            logger.error(e);
        }

        int num = 100;//获取的条数
        int result_num = 100;//获取力行返回的结果数量

        int start_index = 1;
        int end_index = 100;
        while (result_num == num) {

            productCodeSearchRequest.setStart(start_index);
            productCodeSearchRequest.setEnd(end_index);
            List<ProductCodeInfo> productCodeInfoList = null;
            try {
                productCodeInfoList = productDao.getUpdateProductInfo(productCodeSearchRequest);
                if(null != productCodeInfoList){
                    result_num = productCodeInfoList.size();
                    for (ProductCodeInfo p : productCodeInfoList) {
                        if (type == 0 || type == 1) {//全量商品
                            if (!p.getLastUpdateAction().equals("OFF_SHELF")) {
                                mapProductCode.put(p.getProductCode(), p.getLastUpdateAction());
                            }
                        } else if (type == 2 || type == 3) { //选品列表
                            if (null != list_code && list_code.size() > 0 && list_code.contains(p.getProductCode())) {
                                mapProductCode.put(p.getProductCode(), p.getLastUpdateAction());
                            }
                        }

                    }
                }
                start_index = start_index + num;
                end_index = end_index + num;
            } catch (Exception e) {
                logger.error(e);
            }
        }

        logger.info("总共商品：" + mapProductCode.size());
        return mapProductCode;
    }

    /**
     * 定时批量插入接送信息接口
     *
     * @param productCodeList 产品编号列表
     */
    @Override
    public void insertPickDropBatch(List<String> productCodeList) {
        //list的长度
        int length = productCodeList.size();
        //每次允许查询的最大值
        int pageSize = 50;
        //根据每次查询的最大值计算次数，可以查几次
        int pageCount = length % pageSize == 0 ? (length / pageSize) : (length / pageSize + 1);
        //按次数查询，list最大为200，包含200
        for (int i = 0; i < pageCount; i++) {
            //查询的起始记录
            int start = i * pageSize;
            //查询的结束记录
            int end = (i + 1) * pageSize;
            //结束记录超出list的长度，使用list的长度
            if (end > length) {
                end = length;
            }
            //获取查询的条数
            List<String> subList = productCodeList.subList(start, end);
            try {
                PickOrDropRequest pickOrDropRequest = new PickOrDropRequest();
                pickOrDropRequest.setProductCode(subList);
                List<ProductPickInfo> productPickInfoList = productDao.getPickOrDrop(pickOrDropRequest);
                if (null != productPickInfoList && productPickInfoList.size() > 0) {
                    for (ProductPickInfo productPickInfo : productPickInfoList) {
                        if (null != productPickInfo.getPickList() && productPickInfo.getPickList().size() > 0) {
                            for (PickDropModel pickModel : productPickInfo.getPickList()) {
                                pickModel.setProductCode(productPickInfo.getProductCode());
                            }
                            final List<PickDropModel> pickModelList = productPickInfo.getPickList();
                            CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                @Override
                                public Object call() throws Exception {
                                    pickDropMapper.insertPickDrop(pickModelList);
                                    return null;
                                }
                            });
                        }
                        if (null != productPickInfo.getDropList() && productPickInfo.getDropList().size() > 0) {
                            for (PickDropModel dropModel : productPickInfo.getDropList()) {
                                dropModel.setProductCode(productPickInfo.getProductCode());
                            }
                            final List<PickDropModel> dropModelList = productPickInfo.getDropList();
                            CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                @Override
                                public Object call() throws Exception {
                                    pickDropMapper.insertPickDrop(dropModelList);
                                    return null;
                                }
                            });
                        }
                    }
                }
            } catch (Exception e) {
                try {
                    List<TaskErrorLog> taskErrorLogList = new ArrayList<TaskErrorLog>();
                    for (String productCode : subList) {
                        TaskErrorLog taskErrorLog = new TaskErrorLog();
                        taskErrorLog.setParam(productCode);
                        taskErrorLog.setMethodName("updateBatchPickDrop");
                        taskErrorLogList.add(taskErrorLog);
                    }
                    taskErrorLogMapper.insertBatchTaskErrorLog(taskErrorLogList);
                } catch (Exception e1) {
                    logger.error(e1);
                }
                logger.error(e);
            }
        }
    }

    /**
     * 批量删除指定的接送信息
     *
     * @param ids 需要删除的ID集合
     * @return 返回删除结果
     * @throws Exception
     */
    @Override
    public int deleteBacthByPrimaryKey(List<Integer> ids) {
        try {
            return pickDropMapper.deleteBacthByPrimaryKey(ids);
        } catch (Exception e) {
            logger.error(e);
        }
        return 0;
    }

    /**
     * 根据产品code获取到的产品信息,将产品接送信息批量更新到数据库
     *
     * @param productCodeList 产品号列表
     */
    @Override
    public void updateBatchPickDrop(List<String> productCodeList) {
        //list的长度
        int length = productCodeList.size();
        //每次允许查询的最大值
        int pageSize = 50;
        //根据每次查询的最大值计算次数，可以查几次
        int pageCount = length % pageSize == 0 ? (length / pageSize) : (length / pageSize + 1);
        //按次数查询，list最大为200，包含200
        for (int i = 0; i < pageCount; i++) {
            //查询的起始记录
            int start = i * pageSize;
            //查询的结束记录
            int end = (i + 1) * pageSize;
            //结束记录超出list的长度，使用list的长度
            if (end > length) {
                end = length;
            }
            //获取查询的条数
            List<String> subList = productCodeList.subList(start, end);
            try {
                PickOrDropRequest pickOrDropRequest = new PickOrDropRequest();
                List<PickDropModel> emailPickDropList = new ArrayList<PickDropModel>();
                pickOrDropRequest.setProductCode(subList);
                List<ProductPickInfo> productPickInfoList = productDao.getPickOrDrop(pickOrDropRequest);
                if (null != productPickInfoList && productPickInfoList.size() > 0) {
                    for (ProductPickInfo productPickInfo : productPickInfoList) {
                        if (null != productPickInfo.getPickList() && productPickInfo.getPickList().size() > 0) {
                            for (PickDropModel pickModel : productPickInfo.getPickList()) {
                                pickModel.setProductCode(productPickInfo.getProductCode());
                            }
                            final List<PickDropModel> pickModelList = productPickInfo.getPickList();
                            final String productCode = productPickInfo.getProductCode();
                            PickDropModel pickDropModel = new PickDropModel();
                            pickDropModel.setProductCode(productPickInfo.getProductCode());
                            pickDropModel.setType("PICKUP");
                            List<PickDropModel> pickDropModelLocal = pickDropMapper.setlectPickDrop(pickDropModel);
                            if (null != pickDropModelLocal && pickDropModelLocal.size() > 0) {
                                List<PickDropModel> emailPickDropModelList = compareToPickDrop(pickModelList, pickDropModelLocal);
                                if (null != emailPickDropModelList && emailPickDropModelList.size() > 0) {
                                    emailPickDropList.addAll(emailPickDropModelList);
                                    CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                        @Override
                                        public Object call() throws Exception {
                                            pickDropMapper.deleteByProductCode(productCode);
                                            pickDropMapper.insertPickDrop(pickModelList);
                                            return null;
                                        }
                                    });
                                }
                            } else {
                                emailPickDropList.addAll(pickModelList);
                                CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                    @Override
                                    public Object call() throws Exception {
                                        pickDropMapper.insertPickDrop(pickModelList);
                                        return null;
                                    }
                                });
                            }
                        }
                        if (null != productPickInfo.getDropList() && productPickInfo.getDropList().size() > 0) {
                            for (PickDropModel dropModel : productPickInfo.getDropList()) {
                                dropModel.setProductCode(productPickInfo.getProductCode());
                            }
                            final List<PickDropModel> dropModelList = productPickInfo.getDropList();
                            final String productCode = productPickInfo.getProductCode();
                            PickDropModel pickDropModel = new PickDropModel();
                            pickDropModel.setProductCode(productPickInfo.getProductCode());
                            pickDropModel.setType("DROPOFF");
                            List<PickDropModel> pickDropModelLocal = pickDropMapper.setlectPickDrop(pickDropModel);
                            if (null != pickDropModelLocal && pickDropModelLocal.size() > 0) {
                                List<PickDropModel> emailPickDropModelList = compareToPickDrop(dropModelList, pickDropModelLocal);
                                if (null != emailPickDropModelList && emailPickDropModelList.size() > 0) {
                                    emailPickDropList.addAll(emailPickDropModelList);
                                    CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                        @Override
                                        public Object call() throws Exception {
                                            pickDropMapper.deleteByProductCode(productCode);
                                            pickDropMapper.insertPickDrop(dropModelList);
                                            return null;
                                        }
                                    });
                                }
                            } else {
                                emailPickDropList.addAll(dropModelList);
                                CommonThreadPool.execute(new AbstractAroundAdviceCallable() {
                                    @Override
                                    public Object call() throws Exception {
                                        pickDropMapper.insertPickDrop(dropModelList);
                                        return null;
                                    }
                                });
                            }
                        }
                    }
                }
                /**
                 * 发送邮件
                 */
                if(null != emailPickDropList && emailPickDropList.size() > 0){
                    sendEmailService.pickAndDropSendMail(emailPickDropList);
                }
            } catch (Exception e) {
                try {
                    List<TaskErrorLog> taskErrorLogList = new ArrayList<TaskErrorLog>();
                    for (String productCode : subList) {
                        TaskErrorLog taskErrorLog = new TaskErrorLog();
                        taskErrorLog.setParam(productCode);
                        taskErrorLog.setMethodName("updateBatchPickDrop");
                        taskErrorLogList.add(taskErrorLog);
                    }
                    taskErrorLogMapper.insertBatchTaskErrorLog(taskErrorLogList);
                } catch (Exception e1) {
                    logger.error(e1);
                }
                logger.error(e.getMessage());
            }
        }
    }

    /**
     * 删除指定产品的接送信息
     *
     * @param productCode 需要删除的productCode
     * @return 返回删除结果
     * @throws Exception
     */
    @Override
    public int deleteByProductCode(String productCode) {
        try {
            return pickDropMapper.deleteByProductCode(productCode);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return 0;
    }

    private List<PickDropModel> compareToPickDrop(List<PickDropModel> pickDropModels, List<PickDropModel> pickDropModelTarget) {
        if ((null == pickDropModels && pickDropModels.size() <= 0) || (null == pickDropModelTarget && pickDropModelTarget.size() <= 0)) {
            return null;
        }
        List<PickDropModel> pickDropModelList = new ArrayList<PickDropModel>();
        Map<String, Object> map = new HashMap<String, Object>();
        Iterator<PickDropModel> iterator = pickDropModelTarget.iterator();
        while (iterator.hasNext()) {
            PickDropModel pickDropModelIter = iterator.next();
            map.put(pickDropModelIter.getCode(), pickDropModelIter);
        }
        for (PickDropModel pickDropModel : pickDropModels) {
            if (pickDropModel.compareTo((PickDropModel) map.get(pickDropModel.getCode())) != 0) {
                PickDropModel pickDropModelId = (PickDropModel) map.get(pickDropModel.getCode());
                pickDropModel.setId(pickDropModelId.getId());
                pickDropModelList.add(pickDropModel);
            }
        }
        return pickDropModelList;
    }

    /**
     * 获取产品详细信息
     *
     * @param productInfoRequest 获取产品信息调用参数
     * @return 返回产品信息
     * @throws Exception
     */
    public ProductInfo getProductInfo(ProductInfoRequest productInfoRequest) {
        if (null == productInfoRequest) {
            return null;
        }

        try {
            return productDao.getProductInfo(productInfoRequest);
        } catch (Exception e) {
            logger.error("调取力行接口失败：", e);
        }
        return null;
    }

    /**
     * 插入产品信息
     *
     * @param model
     * @return
     */
    public int insertProductInfo(ProductInfo model) {
        if (null != model) {
            if (null != model.getCityCode()) {
                Location lo = locationMapper.getLocationByCode(model.getCityCode());
                if (null != lo) {
                    model.setCityName(lo.getNameCn());
                }
            }
            if (null != model.getRegionCode()) {
                Location lo = locationMapper.getLocationByCode(model.getRegionCode());
                if (null != lo) {
                    model.setRegionName(lo.getNameCn());
                }
            }
            if (null != model.getCountryCode()) {
                Location lo = locationMapper.getLocationByCode(model.getCountryCode());
                if (null != lo) {
                    model.setCountryName(lo.getNameCn());
                }
            }
            if (null != model.getContinentCode()) {
                Location lo = locationMapper.getLocationByCode(model.getContinentCode());
                if (null != lo) {
                    model.setContinentName(lo.getNameCn());
                }
            }
        }

        return productInfoMapper.insertProductInfo(model);
    }

    /**
     * 获得产品信息
     *
     * @return
     */
    public ProductInfo getProductInfo(String productCode) {
        return productInfoMapper.getProductInfo(productCode);
    }

    /**
     * 插入产品预定问题信息
     *
     * @param model
     * @return
     */
    public int insertProductBookQuestion(ProductBookQuestion model) {
        return productInfoMapper.insertProductBookQuestion(model);
    }

    /**
     * 插入产品描述信息
     *
     * @param model
     * @return
     */
    public int insertProductDesc(ProductDesc model) {
        return productInfoMapper.insertProductDesc(model);
    }

    /**
     * 插入产品扩展字段信息
     *
     * @param model
     * @return
     */
    public int insertProductExtendPropertie(ProductExtendPropertie model) {
        return productInfoMapper.insertProductExtendPropertie(model);
    }

    /**
     * 获得产品描述信息
     *
     * @return
     */
    public List<ProductDesc> getProductDesc(String productCode) {
        return productInfoMapper.getProductDesc(productCode);
    }

    /**
     * 插入产品规格信息
     *
     * @param model
     * @return
     */
    public int insertProductInclude(ProductInclude model) {
        return productInfoMapper.insertProductInclude(model);
    }

    /**
     * 获得产品规格
     *
     * @return
     */
    public List<ProductInclude> getProductInclude(String specficationId) {
        return productInfoMapper.getProductInclude(specficationId);
    }

    /**
     * 插入产品行程描述
     *
     * @param model
     * @return
     */
    public int insertProductItinerary(ProductItinerary model) {
        return productInfoMapper.insertProductItinerary(model);
    }

    /**
     * 获得产品行程描述
     *
     * @return
     */
    public List<ProductItinerary> getProductItinerary(String productCode) {
        return productInfoMapper.getProductItinerary(productCode);
    }


    /**
     * 插入产品行程描述酒店信息
     *
     * @param model
     * @return
     */
    public int insertProductItineraryHotel(ProductItineraryHotel model) {
        return productInfoMapper.insertProductItineraryHotel(model);
    }

    /**
     * 获得产品行程描述酒店信息
     *
     * @return
     */
    public ProductItineraryHotel getProductItineraryHotel(int itineraryId) {
        return productInfoMapper.getProductItineraryHotel(itineraryId);
    }

    /**
     * 插入产品行程描述交通信息
     *
     * @param model
     * @return
     */
    public int insertProductItineraryTraffic(ProductItineraryTraffic model) {
        return productInfoMapper.insertProductItineraryTraffic(model);
    }

    /**
     * 获得产品行程描述交通信息
     *
     * @return
     */
    public ProductItineraryTraffic getProductItineraryTraffic(int itineraryId) {
        return productInfoMapper.getProductItineraryTraffic(itineraryId);
    }

    /**
     * 插入产品图片信息
     *
     * @param model
     * @return
     */
    public int insertProductPhoto(ProductPhoto model) {
        return productInfoMapper.insertProductPhoto(model);
    }

    /**
     * 获得产品行程描述交通信息
     *
     * @return
     */
    public List<ProductPhoto> getProductPhoto(String productCode) {
        return productInfoMapper.getProductPhoto(productCode);
    }

    /**
     * 插入产品规格信息
     *
     * @param model
     * @return
     */
    public int insertProductSpecfication(ProductSpecfication model) {
        return productInfoMapper.insertProductSpecfication(model);
    }

    /**
     * 获得产品产品规格信息
     *
     * @return
     */
    public List<ProductSpecfication> getProductSpecfication(String productCode) {
        return productInfoMapper.getProductSpecfication(productCode);
    }

    /**
     * 插入销售项目详细信息
     *
     * @param model
     * @return
     */
    public int insertSaleItemDetail(SaleItemDetail model) {
        return productInfoMapper.insertSaleItemDetail(model);
    }

    /**
     * 获得产品销售项目详细信息
     *
     * @return
     */
    public List<SaleItemDetail> getSaleItemDetail(String productCode) {
        return productInfoMapper.getSaleItemDetail(productCode);
    }

    /**
     * 插入销售项目附加信息
     *
     * @param model
     * @return
     */
    public int insertSaleItemAdditionalOption(SaleItemAdditionalOption model) {
        return productInfoMapper.insertSaleItemAdditionalOption(model);
    }

    /**
     * 插入销售项目自取地址信息
     *
     * @param model
     * @return
     */
    public int insertSaleItemAddressDetail(SaleItemAddressDetail model) {
        return productInfoMapper.insertSaleItemAddressDetail(model);
    }

    /**
     * 插入销售项目凭证信息
     *
     * @param model
     * @return
     */
    public int insertSaleItemVoucherInfo(SaleItemVoucherInfo model) {
        return productInfoMapper.insertSaleItemVoucherInfo(model);
    }

    /**
     * 获得产品销售项目详细信息
     *
     * @return
     */
    public SaleItemVoucherInfo getSaleItemVoucherInfo(String saleCode) {
        return productInfoMapper.getSaleItemVoucherInfo(saleCode);
    }

    /**
     * 获取接送信息
     *
     * @return
     */
    public List<PickDropModel> getPickDrop(String productCode) {
        return pickDropMapper.getPickDrop(productCode);
    }

    /**
     * 获得产品行程酒店图片
     *
     * @return
     */
    public List<ProductPhoto> getPhotoByItinerariesId(String itinerariesId) {
        return productInfoMapper.getPhotoByItinerariesId(itinerariesId);
    }

    /**
     * 获取所有问题
     *
     * @param productCode
     * @return
     */
    public List<ProductBookQuestion> getQuestion(String productCode) {
        return productInfoMapper.getQuestion(productCode);
    }


    /**
     * 根据问题获取答案
     *
     * @param productCode
     * @param questionId
     * @return
     */
    public List<ProductBookQuestion> getQuestionAnswer(String productCode, String questionId) {
        return productInfoMapper.getQuestionAnswer(productCode, questionId);
    }

    /**
     * 删除产品信息
     *
     * @param productCode
     */
    public void deleteProductInfo(String productCode) {
        this.productInfoMapper.deleteProductInfo(productCode);
    }

    /**
     * 删除预定问题
     *
     * @param productCode
     */
    public void deleteProductBookQuestion(String productCode) {
        this.productInfoMapper.deleteProductBookQuestion(productCode);
    }

    /**
     * 删除产品描述
     *
     * @param productCode
     */
    public void deleteProductDescn(String productCode) {
        this.productInfoMapper.deleteProductDescn(productCode);
    }

    /**
     * 删除产品扩展信息
     *
     * @param productCode
     */
    public void deleteProductExtendPropertie(String productCode) {
        this.productInfoMapper.deleteProductExtendPropertie(productCode);
    }

    /**
     * 删除产品附加信息
     *
     * @param productCode
     */
    public void deleteProductInclude(String productCode) {
        this.productInfoMapper.deleteProductInclude(productCode);
    }

    /**
     * 删除产品行程信息
     *
     * @param productCode
     */
    public void deleteProductItinerary(String productCode) {
        this.productInfoMapper.deleteProductItinerary(productCode);
    }

    /**
     * 删除产品行程酒店
     *
     * @param productCode
     */
    public void deleteProductItineraryHotel(String productCode) {
        this.productInfoMapper.deleteProductItineraryHotel(productCode);
    }

    /**
     * 删除产品行程交通信息
     *
     * @param productCode
     */
    public void deleteProductItineraryTraffic(String productCode) {
        this.productInfoMapper.deleteProductItineraryTraffic(productCode);
    }

    /**
     * 删除产品图片信息
     *
     * @param productCode
     */
    public void deleteProductPhoto(String productCode) {
        this.productInfoMapper.deleteProductPhoto(productCode);
    }

    /**
     * 删除产品规格
     *
     * @param productCode
     */
    public void deleteProductSpecfication(String productCode) {
        this.productInfoMapper.deleteProductSpecfication(productCode);
    }

    /**
     * 删除产品销售项目
     *
     * @param productCode
     */
    public void deleteSaleItemDetail(String productCode) {
        this.productInfoMapper.deleteSaleItemDetail(productCode);
    }

    /**
     * 删除产品销售附加信息
     *
     * @param productCode
     */
    public void deleteSaleItemAdditionalOption(String productCode) {
        this.productInfoMapper.deleteSaleItemAdditionalOption(productCode);
    }

    /**
     * 删除产品销售自取地址细腻
     *
     * @param productCode
     */
    public void deleteSaleItemAddressDetail(String productCode) {
        this.productInfoMapper.deleteSaleItemAddressDetail(productCode);
    }

    /**
     * 删除产品凭证信息
     *
     * @param productCode
     */
    public void deleteSaleItemVoucherInfo(String productCode) {
        this.productInfoMapper.deleteSaleItemVoucherInfo(productCode);
    }

    /**
     * 根据销售code获取销售项目信息
     *
     * @param saleCode
     * @return
     */
    public SaleItemDetail getSaleItemDetailBySaleCode(String saleCode) {
        return productInfoMapper.getSaleItemDetailBySaleCode(saleCode);
    }

    /**
     * 根据产品code获取json的信息
     *
     * @param productCode
     * @return
     */
    public Lastminute_all getInfoByProductCode(String productCode) {
        ProductInfo info = this.getProductInfo(productCode);
        if (null != info) {

            /*****************************产品信息**************************************/
            Lastminute_main l_main = new Lastminute_main();
            l_main.setProductCode(productCode);
            l_main.setCity(info.getCityName());
            l_main.setContinent(info.getContinentName());
            l_main.setCountry(info.getCountryName());
            l_main.setProduct_type(info.getProductType());
            l_main.setStart_pos(info.getDepartName());
            l_main.setSupplierid("Lixing");
            l_main.setTitle(info.getProductName());

            /*****************************产品初始价格**************************************/
            Lastminute_info l_info = new Lastminute_info();
            l_info.setProductCode(productCode);
            l_info.setPrice(info.getNetPriceFrom());
            l_info.setList_price(info.getRetailPriceFrom());
            l_info.setPic(info.getMainPic());

            List<SaleItemDetail> list_saleDetail = this.getSaleItemDetail(productCode);
            List<ProductSpecfication> list_spec = this.getProductSpecfication(productCode);

            List<Lastminute_products> list_products = new ArrayList<Lastminute_products>();
            if (null != list_spec && list_spec.size() > 0) {
                for (ProductSpecfication spec : list_spec) {
                    String crowdName = "";
//                    if("PERSON".equals(spec.getSpecificationType())){
//                        if("P1".equals(spec.getSpecificationId())){
//                            crowdName="成人";
//                        }else if("P2".equals(spec.getSpecificationId())){
//                            crowdName="儿童";
//                        }else if("P3".equals(spec.getSpecificationId())){
//                            crowdName="婴儿";
//                        }else if("P4".equals(spec.getSpecificationId())){
//                            crowdName="青年";
//                        }else if("P5".equals(spec.getSpecificationId())){
//                            crowdName="老年";
//                        }
//                    }else{
                    crowdName = spec.getNameCn();
//                    }

                    if (null != list_saleDetail && list_saleDetail.size() > 0) {
                        for (SaleItemDetail saleDetail : list_saleDetail) {
                            List<String> listSpecId=priceMapper.getSpecId(saleDetail.getSaleCode());
                            if(listSpecId.contains(spec.getSpecificationId())){
                                Lastminute_products l_product = new Lastminute_products();
                                l_product.setProductCode(productCode);
                                l_product.setSaleCode(saleDetail.getSaleCode());
                                l_product.setCodeSpecficationId(saleDetail.getSaleCode() + spec.getSpecificationId());
                                l_product.setTitle(saleDetail.getSaleName() + crowdName);
                                list_products.add(l_product);
                            }

                        }
                    }
                }

            }

            //玩乐大字段

            /********************************产品相关************************************/
            Map<String,Object> content_data_list = new HashMap<String, Object>();
            //产品信息
            StringBuffer sb_productInfo=new StringBuffer("<p>");
            sb_productInfo.append("产品信息：").append(info.getShortDescription()).append("<br/>");
            Map<String, Object> product_info = new HashMap<String, Object>();
            product_info.put("name", "产品信息");
            sb_productInfo.append("产品特色：").append(info.getSalePoints_str()).append("<br/>");
            if (null != sb_productInfo && !sb_productInfo.toString().equals("")) {
                product_info.put("is_forced_select", true);
            } else {
                product_info.put("is_forced_select", false);
            }
            sb_productInfo.append("</p>");
            product_info.put("is_checked", true);
            product_info.put("editor_content", sb_productInfo.toString());
            product_info.put("id", "product_info");
            //产品介绍
            Map<String, Object> spot_introduce = new HashMap<String, Object>();
            spot_introduce.put("name", "景点介绍");
            spot_introduce.put("is_checked", true);
            List<ProductDesc> list_desc = this.getProductDesc(productCode);
            StringBuffer sb_desc = new StringBuffer("<p>");
            if (null != list_desc && list_desc.size() > 0) {
                for (ProductDesc desc : list_desc) {
                    sb_desc.append(desc.getContent()).append("<br/>");
                }
            }
            spot_introduce.put("editor_content", sb_desc.toString());
            if (null != sb_desc && !sb_desc.toString().equals("")) {
                spot_introduce.put("is_forced_select", true);
            } else {
                spot_introduce.put("is_forced_select", false);
            }
            spot_introduce.put("id", "spot_introduce");

            //重要提示
            Map<String, Object> important_tip = new HashMap<String, Object>();
            important_tip.put("name", "重要提示");
            StringBuffer question_sb = new StringBuffer("<p>");
            List<ProductBookQuestion> list_question = this.getQuestion(productCode);
            if (null != list_question && list_question.size() > 0) {
                int i = 0;
                for (ProductBookQuestion question : list_question) {
                    i++;
                    question_sb.append("预定问题" + i + ":").append(question.getContent()).append("<br/>");
                    List<ProductBookQuestion> list_answer = this.getQuestionAnswer(productCode, question.getQuestionId());
                    if (null != list_answer && list_answer.size() > 0) {
                        question_sb.append("答案：").append("<br/>");
                        for (ProductBookQuestion answer : list_answer) {
                            question_sb.append(answer.getAnswerContent()).append("<br/>");
                        }
                    }
                }
            }
            if (null != question_sb && !question_sb.toString().equals("")) {
                important_tip.put("is_forced_select", true);
            } else {
                important_tip.put("is_forced_select", false);
            }
            question_sb.append("</p>");
            important_tip.put("is_checked", true);
            important_tip.put("editor_content", question_sb.toString());
            important_tip.put("id", "important_tip");

            //更多信息
            Map<String, Object> more_product_info = new HashMap<String, Object>();
            more_product_info.put("name", "更多信息");
            more_product_info.put("is_forced_select", false);
            more_product_info.put("is_checked", true);
            more_product_info.put("editor_content", "<p></p>");
            more_product_info.put("id", "more_product_info");

            content_data_list.put("product_info",product_info);
            content_data_list.put("spot_introduce",spot_introduce);
            content_data_list.put("important_tip",important_tip);
            content_data_list.put("more_product_info",more_product_info);

            Map<String, Object> product_introduce = new HashMap<String, Object>();
            product_introduce.put("name", "产品介绍");
            product_introduce.put("is_necessary", false);
            product_introduce.put("content_type", "editor");
            product_introduce.put("content_data_list", content_data_list);
            product_introduce.put("order", 2);
            product_introduce.put("id", "product_introduce");

            /********************************费用相关************************************/
            Map<String,Object> content_data_list_cost = new HashMap<String,Object>();
            //费用包含
            StringBuffer sb_cost=new StringBuffer("<p>");
            sb_cost.append(info.getInclusions());
            Map<String, Object> cost_include = new HashMap<String, Object>();
            cost_include.put("name", "费用包含");
            if (null != sb_cost && !sb_cost.toString().equals("")) {
                cost_include.put("is_forced_select", true);
            } else {
                cost_include.put("is_forced_select", false);
            }
            sb_cost.append("</p>");
            cost_include.put("is_checked", true);
            cost_include.put("editor_content", sb_cost.toString());
            cost_include.put("id", "cost_include");
            //费用不含
            Map<String, Object> cost_exclude = new HashMap<String, Object>();
            StringBuffer sb_ex=new StringBuffer("<p>");
            sb_ex.append(info.getExclusions());
            cost_exclude.put("name", "费用不含");
            if (null != sb_ex && !sb_ex.toString().equals("")) {
                cost_exclude.put("is_forced_select", true);
            } else {
                cost_exclude.put("is_forced_select", false);
            }
            cost_exclude.put("is_checked", true);
            sb_ex.append("</p>");
            cost_exclude.put("editor_content", sb_ex.toString());
            cost_exclude.put("id", "cost_exclude");

            //赠送项目
            Map<String, Object> present = new HashMap<String, Object>();
            present.put("name", "赠送项目");
            present.put("is_forced_select", false);
            present.put("is_checked", false);
            present.put("editor_content", "<p></p>");
            present.put("id", "present");

            content_data_list_cost.put("cost_include",cost_include);
            content_data_list_cost.put("cost_exclude",cost_exclude);
            content_data_list_cost.put("present",present);

            Map<String, Object> cost = new HashMap<String, Object>();
            cost.put("name", "费用");
            cost.put("is_necessary", false);
            cost.put("content_type", "editor");
            cost.put("content_data_list", content_data_list_cost);
            cost.put("order", 4);
            cost.put("id", "cost");




            /********************************预定须知相关************************************/
            Map<String,Object> content_data_list_book = new HashMap<String, Object>();
            //预定须知
            StringBuffer sb_prebook=new StringBuffer("<p>");
            sb_prebook.append("预定须知：").append(info.getAttentions()).append("<br/>");
            Map<String, Object> prebook = new HashMap<String, Object>();
            prebook.put("name", "预定流程");

            String book_str = "";//预定方式

            String supply_str = "";//出票方式

            String valid_time_desc_str = "";//有效期描述

            String restriction_str = "";//限制条件
            for (SaleItemDetail detail : list_saleDetail) {

                String s = detail.getBookMethod();
                if (s.equals("NO_CONFIRM")) {
                    book_str = "立即确认";
                } else if (s.equals("NEED_CONFIRM")) {
                    book_str = "需要确认";
                } else if (s.equals("API_NEED_CONFIRM")) {
                    book_str = "需要确认";
                }

                String s1 = detail.getSupplyMethod();
                if (s1.equals("NO_CONFIRM")) {
                    supply_str = "立即确认";
                } else if (s1.equals("NEED_CONFIRM")) {
                    supply_str = "需要确认";
                } else if (s1.equals("API_NEED_CONFIRM")) {
                    supply_str = "需要确认";
                }
                valid_time_desc_str = detail.getValidTimeDesc();
                restriction_str = detail.getRestriction();
                if (null == restriction_str || restriction_str.equals("")) {
                    continue;
                }
                break;
            }
            if(null==book_str|| QyerUtils.isEmpty(book_str)){
                book_str="";
            }
            sb_prebook.append("预定方式：").append(book_str).append("<br/>");

            if(null==supply_str|| QyerUtils.isEmpty(supply_str)){
                supply_str="";
            }
            sb_prebook.append("出票方式：").append(supply_str).append("<br/>");

            if(null==valid_time_desc_str|| QyerUtils.isEmpty(valid_time_desc_str)){
                valid_time_desc_str="";
            }
            sb_prebook.append("有效期描述：").append(valid_time_desc_str).append("<br/>");

            if(null==restriction_str|| QyerUtils.isEmpty(restriction_str)){
                restriction_str="";
            }
            sb_prebook.append("限制条件：").append(restriction_str).append("<br/>");


            if (null != sb_prebook && !sb_prebook.toString().equals("")) {
                prebook.put("is_forced_select", true);
            } else {
                prebook.put("is_forced_select", false);
            }
            sb_prebook.append("</p>");
            prebook.put("is_checked", true);
            prebook.put("editor_content", sb_prebook.toString());
            prebook.put("id", "prebook");

            //退改政策
            Map<String, Object> refund_policy = new HashMap<String, Object>();
            refund_policy.put("name", "退款政策");

            String refund_str = "";
            for (SaleItemDetail detail : list_saleDetail) {
                List<Price> list_price = priceMapper.getPrice(detail.getSaleCode());
                if (null != list_price && list_price.size() > 0) {
                    for (Price price : list_price) {
                        refund_str = price.getCancellation();
                        if (null == refund_str || refund_str.equals("")) {
                            continue;
                        }
                        break;
                    }
                }
                break;
            }
            if (null != refund_str && !refund_str.equals("")) {
                refund_policy.put("is_forced_select", true);
            } else {
                refund_policy.put("is_forced_select", false);
            }
            refund_policy.put("is_checked", true);
            refund_policy.put("editor_content", "<p>"+refund_str+"</p>");
            refund_policy.put("id", "refund_policy");


            //兑换信息
            StringBuffer sb_award=new StringBuffer("<p>");
            Map<String, Object> award_info = new HashMap<String, Object>();
            award_info.put("name", "兑换信息");
            String voucher_str = "";//使用说明
            String use_notice = "";//使用注意
            String voucher_option_str = "";//兑换详情
            for (SaleItemDetail detail : list_saleDetail) {
                SaleItemVoucherInfo voucher = this.getSaleItemVoucherInfo(detail.getSaleCode());
                if (null != voucher) {
                    if (null != voucher.getUseTips_str() && !voucher.getUseTips_str().equals("")) {
                        String[] voucher_array = voucher.getUseTips_str().split("\\|");
                        for (String s : voucher_array) {
                            voucher_str = voucher_str + s + "<br/>";
                        }
                        use_notice = voucher.getNotice();
                        voucher_option_str = detail.getVoucherOption();
                        break;
                    }


                }

            }
            if(null==voucher_str|| QyerUtils.isEmpty(voucher_str)){
                voucher_str="";
            }
            sb_award.append("凭证信息：").append(voucher_str).append("<br/>");

            if(null==use_notice|| QyerUtils.isEmpty(use_notice)){
                use_notice="";
            }
            sb_award.append("注意事项：").append(use_notice).append("<br/>");

            if(null==voucher_option_str|| QyerUtils.isEmpty(voucher_option_str)){
                voucher_option_str="";
            }
            sb_award.append("兑换详情：").append(voucher_option_str).append("<br/>");

            if(null==info.getDepartureRemark()|| QyerUtils.isEmpty(info.getDepartureRemark())){
                info.setDepartureRemark("");
            }
            sb_award.append("集合信息：").append(info.getDepartureRemark()).append("<br/>");

            StringBuffer pick_str = new StringBuffer();
            List<PickDropModel> list_pick = this.getPickDrop(productCode);
            if (null != list_pick && list_pick.size() > 0) {
                for (PickDropModel pick : list_pick) {
                    pick_str.append(pick.getTime()).append("\t").append(pick.getLocation()).append("\t").append(pick.getAddress()).append("<br/>");
                }
            }

            sb_award.append("集合地点：").append(pick_str.toString()).append("<br/>");

            if(null==info.getDropOffRemark()|| QyerUtils.isEmpty(info.getDropOffRemark())){
                info.setDropOffRemark("");
            }
            sb_award.append("解散信息：").append(info.getDropOffRemark()).append("<br/>");

            if(null==info.getDepartureTime()|| QyerUtils.isEmpty(info.getDepartureTime())){
                info.setDepartureTime("");
            }
            sb_award.append("营业时间：").append(info.getDepartureTime()).append("<br/>");

            if(null==info.getDeparturePoint()|| QyerUtils.isEmpty(info.getDeparturePoint())){
                info.setDeparturePoint("");
            }
            sb_award.append("营业地点：").append(info.getDeparturePoint()).append("<br/>");

            if (null != sb_award && !sb_award.toString().equals("")) {
                award_info.put("is_forced_select", true);
            } else {
                award_info.put("is_forced_select", false);
            }
            sb_award.append("</p>");
            award_info.put("is_checked", true);
            award_info.put("editor_content", sb_award.toString());
            award_info.put("id", "award_info");



            content_data_list_book.put("prebook",prebook);
            content_data_list_book.put("refund_policy",refund_policy);
            content_data_list_book.put("award_info",award_info);

            Map<String, Object> use_explan = new HashMap<String, Object>();
            use_explan.put("name", "预定须知");
            use_explan.put("is_necessary", false);
            use_explan.put("content_type", "editor");
            use_explan.put("content_data_list", content_data_list_book);
            use_explan.put("order", 5);
            use_explan.put("id", "use_explan");


            /********************************行程相关************************************/
            Map<String,Object> content_data_list_travel = new HashMap<String, Object>();
            //预定方式
            Map<String, Object> refer_travel = new HashMap<String, Object>();
            refer_travel.put("name", "参考行程");


            StringBuffer travel_str = new StringBuffer("<p>");//行程安排
            List<ProductItinerary> list_itin = this.getProductItinerary(productCode);
            if (null != list_itin && list_itin.size() > 0) {
                for (ProductItinerary itinerary : list_itin) {
                    travel_str.append(itinerary.getItineraryTitle()).append("<br/>");
                    String b_content = "";//早餐
                    String l_content = "";//午餐
                    String d_content = "";//晚餐
                    if (null != itinerary.getBreakfastDescription()) {
                        b_content = itinerary.getBreakfastDescription();
                    }
                    if (null != itinerary.getLunchDescription()) {
                        l_content = itinerary.getLunchDescription();
                    }
                    if (null != itinerary.getDinnerDescription()) {
                        d_content = itinerary.getDinnerDescription();
                    }
                    if (!b_content.equals("") && !l_content.equals("") && !d_content.equals("")) {
                        travel_str.append("早餐：").append(b_content).append(",").append("午餐：").append(l_content).append(",").append("晚餐：").append(d_content).append("<br/>");
                    }
                    ProductItineraryTraffic traffic = this.getProductItineraryTraffic(itinerary.getId());
                    if (null != traffic) {
                        travel_str.append("交通安排：").append(traffic.getDeparture()).append("-").append(traffic.getArrival()).append("<br/>");
                        travel_str.append("交通信息：").append(traffic.getTrafficInfo()).append("<br/>");
                    }
                    ProductItineraryHotel traffic_hotel = this.getProductItineraryHotel(itinerary.getId());
                    if (null != traffic_hotel) {
                        travel_str.append("酒店：").append(traffic_hotel.getHotelName()).append("<br/>");
                        travel_str.append("星级：").append(traffic_hotel.getHotelLevel()).append("<br/>");
                        travel_str.append("地址：").append(traffic_hotel.getHotelAddress()).append("<br/>");
                        List<ProductPhoto> itin_photo = this.getPhotoByItinerariesId(String.valueOf(itinerary.getId()));
                        String p_str = "";
                        if (null != itin_photo && itin_photo.size() > 0) {

                            for (ProductPhoto p : itin_photo) {
                                p_str = p_str + "<img src='" + p.getUrl() + "' width='312px' height='192px' />";
                            }
                        }
                        travel_str.append("酒店图片：").append(p_str).append("<br/>");
                    }
                    travel_str.append("行程介绍:").append(itinerary.getItineraryIntroduce()).append("</p>");
                }
            }

            if (null != travel_str && !travel_str.toString().equals("")) {
                refer_travel.put("is_forced_select", true);
            } else {
                refer_travel.put("is_forced_select", false);
            }
            travel_str.append("</p>");
            refer_travel.put("is_checked", true);
            refer_travel.put("editor_content", travel_str.toString());
            refer_travel.put("id", "refer_travel");

            //更多信息
            Map<String, Object> more_travel_info = new HashMap<String, Object>();
            more_travel_info.put("name", "更多信息");
            more_travel_info.put("is_forced_select", true);
            more_travel_info.put("is_checked", false);
            more_travel_info.put("editor_content", "<p></p>");
            more_travel_info.put("id", "more_travel_info");

            content_data_list_travel.put("refer_travel",refer_travel);
            content_data_list_travel.put("more_travel_info",more_travel_info);

            Map<String, Object> travel_introduce = new HashMap<String, Object>();
            travel_introduce.put("name", "行程安排");
            travel_introduce.put("is_necessary", false);
            travel_introduce.put("content_type", "editor");
            travel_introduce.put("content_data_list", content_data_list_travel);
            travel_introduce.put("order", 3);
            travel_introduce.put("id", "travel_introduce");


            /******************************外层封装*********************************/
            Map<String, Object> cityfun_introduce = new HashMap<String, Object>();
            cityfun_introduce.put("product_introduce", product_introduce);
            cityfun_introduce.put("cost", cost);
            cityfun_introduce.put("use_explan", use_explan);
            cityfun_introduce.put("travel_introduce", travel_introduce);

            Lastminute_introduct lastminute_introduct = new Lastminute_introduct();
            lastminute_introduct.setCityfun_introduce(cityfun_introduce);


//            /******************************价格日历*********************************/
//            List<Lastminute_category> lastminute_category = new ArrayList<Lastminute_category>();
//            for (SaleItemDetail detail : list_saleDetail) {
//                List<Price> list_main_price = priceService.getPrice(detail.getSaleCode());
//                if (null != list_main_price && list_main_price.size() > 0) {
//                    for (Price price : list_main_price) {
//                        if (null != price) {
//                            Lastminute_category category = new Lastminute_category();
//                            category.setNet_price(price.getNetPrice());
//                            category.setRetail_price(price.getRetailPrice());
//                            category.setSaleCode(detail.getSaleCode());
//                            category.setProductCode(productCode);
//                            category.setStart_date(DateUtil.formatDateByFormat(price.getDate(), "yyyy-MM-dd"));
//                            category.setCodeSpecficationId(detail.getSaleCode() + price.getSpecificationId());
//                            lastminute_category.add(category);
//                        }
//
//                    }
//                }
//            }


            Lastminute_all l_all = new Lastminute_all();
            l_all.setLastminute_info(l_info);
            l_all.setLastminute_main(l_main);
            l_all.setLastminute_products(list_products);
            l_all.setLastminute_introduct(lastminute_introduct);
//            l_all.setLastminute_category(lastminute_category);

            return l_all;
        }
        return null;
    }

    /**
     * 执行插入产品数据
     *
     * @param productCode
     * @param status
     */
    public void insertProduct(String productCode, String status) {
        if (null != productCode && !productCode.equals("")) {
            ProductInfoRequest productInfoRequest = new ProductInfoRequest();
            try {
                productInfoRequest.setProductCode(productCode);
                productInfoRequest.setCurrency("CNY");
                productInfoRequest.setNeedSaleInfo("true");
                ProductInfo productInfo = this.getProductInfo(productInfoRequest);
                String salePoints_str = "";
                if (null != productInfo) {
                    productInfo.setFromtime(DateUtil.getCurrentDateTimeToStr3());
                    if (status.equals("RELEASE") || status.equals("UPDATE")) {
                        productInfo.setStatus(1);
                    } else if (status.equals("OFF_SHELF")) {
                        productInfo.setStatus(2);
                    }

                    //产品卖点
                    if (null != productInfo.getSalePoints()) {
                        List<String> listSalePoint = productInfo.getSalePoints();
                        for (String points : listSalePoint) {
                            salePoints_str = salePoints_str + points + "|";
                        }
                        salePoints_str = salePoints_str.substring(0, salePoints_str.lastIndexOf("|"));
                    }

                    //产品卖点
                    productInfo.setSalePoints_str(salePoints_str);
                    try {
                        int result = this.insertProductInfo(productInfo);
                        int productInfoId = productInfo.getId();
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    //产品描述
                    if (null != productInfo.getDescriptions()) {
                        if (null != productInfo.getDescriptions().getProductDescList()) {
                            List<ProductDesc> listDesc = productInfo.getDescriptions().getProductDescList();
                            for (ProductDesc desc : listDesc) {
                                desc.setProductCode(productInfo.getProductCode());
                                try {
                                    int result = this.insertProductDesc(desc);
                                    int descId = desc.getId();
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }

                    //规格信息
                    if (null != productInfo.getProductSpecifications()) {
                        if (null != productInfo.getProductSpecifications().getProductSpecficationList()) {
                            List<ProductSpecfication> listSpec = productInfo.getProductSpecifications().getProductSpecficationList();
                            for (ProductSpecfication model : listSpec) {
                                model.setProductCode(productInfo.getProductCode());
                                try {
                                    int result = this.insertProductSpecfication(model);
                                    int specificationId = model.getId();

                                    //规格组
                                    if (null != model.getIncludeCrowds()) {
                                        if (null != model.getIncludeCrowds().getProductIncludeList()) {
                                            List<ProductInclude> listInclude = model.getIncludeCrowds().getProductIncludeList();
                                            for (ProductInclude include : listInclude) {
                                                include.setSpecificationId(specificationId);
                                                include.setProductCode(productInfo.getProductCode());
                                                try {
                                                    int result1 = this.insertProductInclude(include);
                                                    int includeId = include.getId();
                                                } catch (Exception e) {
                                                    logger.error(e);
                                                }
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }

                    //图片信息
                    if (null != productInfo.getBookPhotos()) {
                        if (null != productInfo.getBookPhotos().getProductPhotoList()) {
                            List<ProductPhoto> listPhoto = productInfo.getBookPhotos().getProductPhotoList();
                            for (ProductPhoto model : listPhoto) {
                                model.setProductCode(productInfo.getProductCode());
                                try {
                                    int result = this.insertProductPhoto(model);
                                    int photoId = model.getId();
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }

                    //预定问题信息
                    if (null != productInfo.getBookQuestions()) {
                        if (null != productInfo.getBookQuestions().getProductBookQuestionList()) {
                            List<ProductBookQuestion> listQuestion = productInfo.getBookQuestions().getProductBookQuestionList();
                            for (ProductBookQuestion model : listQuestion) {
                                model.setProductCode(productInfo.getProductCode());
                                if (null != model.getQuestionId() && !model.getQuestionId().equals("")) {
                                    try {
                                        model.setIsQA(1);//问题
                                        int result = this.insertProductBookQuestion(model);
                                    } catch (Exception e) {
                                        logger.error(e);
                                    }
                                }

                                if (null != model.getBookAnswers() && model.getBookAnswers().size() > 0) {
                                    for (ProductBookAnswer answer : model.getBookAnswers()) {
                                        model.setAnswerCode(answer.getAnswerCode());
                                        model.setAnswerContent(answer.getAnswerContent());
                                        model.setIsQA(2);//答案
                                        try {
                                            int result = this.insertProductBookQuestion(model);
                                        } catch (Exception e) {
                                            logger.error(e);
                                        }
                                    }

                                }

                            }
                        }
                    }

                    //扩展字段
                    if (null != productInfo.getExtendProperties()) {
                        if (null != productInfo.getExtendProperties().getProductExtendPropertieList()) {
                            List<ProductExtendPropertie> listExtend = productInfo.getExtendProperties().getProductExtendPropertieList();
                            for (ProductExtendPropertie model : listExtend) {
                                model.setProductCode(productInfo.getProductCode());
                                try {
                                    int result = this.insertProductExtendPropertie(model);
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }

                    //多日行程描述
                    if (null != productInfo.getItineraries()) {
                        if (null != productInfo.getItineraries().getProductItinerarieList()) {
                            List<ProductItinerary> listItinerary = productInfo.getItineraries().getProductItinerarieList();
                            for (ProductItinerary model : listItinerary) {
                                model.setProductCode(productInfo.getProductCode());
                                //途径景点
                                String attractions_str = "";
                                if (null != model.getAttractions()) {
                                    for (String at : model.getAttractions()) {
                                        attractions_str = attractions_str + at + "|";
                                    }
                                    attractions_str = attractions_str.substring(0, attractions_str.lastIndexOf("|"));
                                }
                                model.setAttractions_str(attractions_str);

                                //行程途径地
                                String routes_str = "";
                                if (null != model.getRoutes()) {
                                    for (String route : model.getRoutes()) {
                                        routes_str = routes_str + route + "|";
                                    }
                                    routes_str = routes_str.substring(0, routes_str.lastIndexOf("|"));
                                }
                                model.setRoutes_str(routes_str);

                                try {
                                    int result = this.insertProductItinerary(model);
                                    int itinerariesId = model.getId();

                                    //行程照片
                                    if (null != model.getItineraryPphotos()) {
                                        if (null != model.getItineraryPphotos().getProductPhotoList()) {
                                            List<ProductPhoto> listPhoto = model.getItineraryPphotos().getProductPhotoList();
                                            for (ProductPhoto photo : listPhoto) {
                                                photo.setItinerariesId(String.valueOf(itinerariesId));
                                                photo.setProductCode(productInfo.getProductCode());
                                                try {
                                                    int result1 = this.insertProductPhoto(photo);
                                                    int photoId = photo.getId();
                                                } catch (Exception e) {
                                                    logger.error(e);
                                                }
                                            }
                                        }
                                    }


                                    //交通信息
                                    if (null != model.getItineraryTraffic()) {
                                        List<ProductItineraryTraffic> listTraffic = model.getItineraryTraffic();
                                        for (ProductItineraryTraffic traffic : listTraffic) {
                                            traffic.setItineraryId(itinerariesId);
                                            traffic.setProductCode(productInfo.getProductCode());
                                            try {
                                                int result2 = this.insertProductItineraryTraffic(traffic);
                                                int trafficId = traffic.getId();
                                            } catch (Exception e) {
                                                logger.error(e);
                                            }
                                        }
                                    }

                                    //酒店信息
                                    if (null != model.getHotels()) {
                                        if (null != model.getHotels().getProductItineraryHotelList()) {
                                            List<ProductItineraryHotel> listHotel = model.getHotels().getProductItineraryHotelList();
                                            for (ProductItineraryHotel hotel : listHotel) {
                                                hotel.setItineraryId(itinerariesId);
                                                hotel.setProductCode(productInfo.getProductCode());
                                                try {
                                                    int result3 = this.insertProductItineraryHotel(hotel);
                                                    int hotelId = hotel.getId();
                                                    if (null != hotel.getHotelPhotos()) {
                                                        if (null != hotel.getHotelPhotos().getProductPhotoList()) {
                                                            List<ProductPhoto> listPhoto = hotel.getHotelPhotos().getProductPhotoList();
                                                            for (ProductPhoto ph : listPhoto) {
                                                                ph.setHotelId(String.valueOf(hotelId));
                                                                ph.setItinerariesId(String.valueOf(itinerariesId));
                                                                ph.setProductCode(productInfo.getProductCode());
                                                                try {
                                                                    int result4 = this.insertProductPhoto(ph);
                                                                    int phId = ph.getId();
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }
                                                            }
                                                        }
                                                    }
                                                } catch (Exception e) {
                                                    logger.error(e);
                                                }
                                            }
                                        }

                                    }
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }

                    //销售项目详细信息
                    if (null != productInfo.getSaleItemDetails()) {
                        if (null != productInfo.getSaleItemDetails().getSaleItemDetailList()) {
                            List<SaleItemDetail> listDetail = productInfo.getSaleItemDetails().getSaleItemDetailList();
                            for (SaleItemDetail model : listDetail) {
                                try {
                                    int result = this.insertSaleItemDetail(model);
                                    int saleItemDetailId = model.getId();
                                } catch (Exception e) {
                                    logger.error(e);
                                }

                                //销售项目凭证信息
                                if (null != model.getVoucherInfo()) {
                                    for (SaleItemVoucherInfo voucher : model.getVoucherInfo()) {
                                        voucher.setSaleCode(model.getSaleCode());
                                        voucher.setProductCode(productInfo.getProductCode());
                                        try {
                                            //usetip
                                            String useTips_str = "";
                                            if (null != voucher.getUseTips()) {
                                                for (String tips : voucher.getUseTips()) {
                                                    useTips_str = useTips_str + tips + "|";
                                                }
                                                useTips_str = useTips_str.substring(0, useTips_str.lastIndexOf("|"));
                                                voucher.setUseTips_str(useTips_str);
                                            }
                                            int result = this.insertSaleItemVoucherInfo(voucher);
                                            int voucherInfoId = voucher.getId();

                                            //自取地址
                                            if (null != voucher.getAddressDetails()) {
                                                for (SaleItemAddressDetail address : voucher.getAddressDetails().getSaleItemAddressDetailList()) {
                                                    address.setVoucherInfoId(voucherInfoId);
                                                    address.setProductCode(productInfo.getProductCode());
                                                    try {
                                                        int result1 = this.insertSaleItemAddressDetail(address);
                                                        int addressId = address.getId();
                                                    } catch (Exception e) {
                                                        logger.error(e);
                                                    }
                                                }
                                            }


                                        } catch (Exception e) {
                                            logger.error(e);
                                        }


                                    }
                                }

                                //销售项目附加信息
                                if (null != model.getAdditionalOptions()) {
                                    if (null != model.getAdditionalOptions().getSaleItemAdditionalOptionList()) {
                                        List<SaleItemAdditionalOption> listAdditionOption = model.getAdditionalOptions().getSaleItemAdditionalOptionList();
                                        for (SaleItemAdditionalOption option : listAdditionOption) {
                                            option.setSaleCode(model.getSaleCode());
                                            option.setProductCode(productInfo.getProductCode());
                                            try {
                                                int result = this.insertSaleItemAdditionalOption(option);
                                            } catch (Exception e) {
                                                logger.error(e);
                                            }
                                        }
                                    }
                                }

                                //扩展字段
                                if (null != model.getExtendProperties()) {
                                    if (null != model.getExtendProperties().getProductExtendPropertieList()) {
                                        List<ProductExtendPropertie> listExtend = model.getExtendProperties().getProductExtendPropertieList();
                                        for (ProductExtendPropertie pro : listExtend) {
                                            model.setProductCode(productInfo.getProductCode());
                                            model.setSaleCode(model.getSaleCode());
                                            try {
                                                int result = this.insertProductExtendPropertie(pro);
                                            } catch (Exception e) {
                                                logger.error(e);
                                            }
                                        }
                                    }
                                }

                                //规格信息
                                if (null != model.getProductSpecifications()) {
                                    if (null != model.getProductSpecifications().getProductSpecficationList()) {
                                        List<ProductSpecfication> listSpec = model.getProductSpecifications().getProductSpecficationList();
                                        for (ProductSpecfication specs : listSpec) {
                                            specs.setProductCode(productInfo.getProductCode());
                                            specs.setSaleCode(model.getSaleCode());
                                            try {
                                                int result = this.insertProductSpecfication(specs);
                                                int specificationId = specs.getId();
                                                //规格组
                                                if (null != specs.getIncludeCrowds()) {
                                                    if (null != specs.getIncludeCrowds().getProductIncludeList()) {
                                                        List<ProductInclude> listInclude = specs.getIncludeCrowds().getProductIncludeList();
                                                        for (ProductInclude include : listInclude) {
                                                            include.setSpecificationId(specificationId);
                                                            try {
                                                                int result1 = this.insertProductInclude(include);
                                                            } catch (Exception e) {
                                                                logger.error(e);
                                                            }
                                                        }
                                                    }
                                                }
                                            } catch (Exception e) {
                                                logger.error(e);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                }

            } catch (Exception e) {
                e.printStackTrace();
                logger.error("错误code" + productCode,e);
            }
        }

    }

    /**
     * 根据产品code,销售code获取价格日历信息
     *
     * @param productCode
     * @return
     */
    public Map<String, List<Lastminute_category>> getPriceBySaleCode(String productCode, String saleCode, String codeSpecficatioinId) {
        ProductInfo info = this.getProductInfo(productCode);
        if (null != info) {
            SaleItemDetail detail = productInfoMapper.getSaleItemDetailBySaleCode(saleCode);
            if (null != detail) {
                /******************************价格日历*********************************/
                List<Lastminute_category> lastminute_category = new ArrayList<Lastminute_category>();
                List<Price> list_main_price = priceMapper.getPrice(detail.getSaleCode());
                if (null != list_main_price && list_main_price.size() > 0) {
                    for (Price price : list_main_price) {
                        if (null != price) {
                            if (codeSpecficatioinId.equals(detail.getSaleCode() + price.getSpecificationId())) {
                                Lastminute_category category = new Lastminute_category();
                                category.setNet_price(price.getNetPrice());
                                category.setRetail_price(price.getRetailPrice());
                                category.setSaleCode(detail.getSaleCode());
                                category.setProductCode(productCode);
                                category.setStart_date(DateUtil.formatDateByFormat(price.getDate(), "yyyy-MM-dd"));
                                category.setCodeSpecficationId(detail.getSaleCode() + price.getSpecificationId());
                                lastminute_category.add(category);
                            }

                        }

                    }
                }
                Map<String, List<Lastminute_category>> map = new HashMap<String, List<Lastminute_category>>();
                map.put("lastminute_category", lastminute_category);

                return map;
            }

        }
        return null;
    }

    /**
     * 获取套餐名称
     *
     * @return 返回套餐名称
     */
    @Override
    public List<SaleItemDetail> getSaleNameMap() {
        return productInfoMapper.getSaleNameMap();
    }
}
